package com.gw2.gw2world;

import java.util.ArrayList;
import java.util.List;

import com.gw2.gw2world.controller.ConfigureEventAdapter;
import com.gw2.gw2world.controller.DatabaseOpenHelper;
import com.gw2.gw2world.controller.Tools;
import com.gw2.gw2world.model.Event;

import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

public class EventConfigurationActivity extends ListActivity {
	private List<Event> events;
	private DatabaseOpenHelper dbHelper;
	private SQLiteDatabase db;
	private Cursor c;
	private ConfigureEventAdapter cea;
	
	@SuppressWarnings("unused")
	private static final String TAG="EventConfigurationActivity";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Tools.forceLocale(this);
		dbHelper = new DatabaseOpenHelper(this, "database", null, 1);
		db=dbHelper.getReadableDatabase();
		events=new ArrayList<Event>();
		cea=new ConfigureEventAdapter(this, events);
		setListAdapter(cea);
	}
	@Override
	protected void onResume() {
		super.onResume();
		updateList();
	}
	void updateList() {
		events.clear();
		c=db.query("master_event", new String[]{"id","name","repeat"}, "chest=1", null, null, null, "level ASC,name ASC");
		while(c.moveToNext()) {
			Event e=new Event();
			e.id=c.getString(0);
			e.name=c.getString(1);
			e.enabled=c.getString(2)==null?false:true;
			events.add(e);
		}
	}
}
